<?php
function replace_specialChar($strParam)
{
    $regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
    $str = preg_replace($regex, "", $strParam);

    $str = trim($str); //清除字符串两边的空格
    $str = preg_replace("/\t/", " ", $str); //使用正则表达式替换内容，如：制表符，并将替换为空格。
    $str = preg_replace("/\r\n/", "<br/>", $str);
    $str = preg_replace("/\r/", "<br/>", $str);
    $str = preg_replace("/\n/", "<br/>", $str);
    $str = preg_replace("/ /", " ", $str);
    $str = preg_replace("/  /", " ", $str);  //匹配html中的空格
    $str = preg_replace("/\"/", "", $str);        //匹配"替换为空
    return $str;
}

function filter()
{
    foreach ($_GET as $key => $value) {
        $_GET[$key] = replace_specialChar($value);
    }
    foreach ($_POST as $key => $value) {
        $_POST[$key] = replace_specialChar($value);
    }
}
